
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
				 java.util.Iterator,
                 com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/addNewEndUserContactPerson.do"/>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</script>

<script language='javascript'>
function save()
{
    var errors = '';
    var contactperson = document.addNewContactPersonForm.newContactPerson.value;
    var email = document.addNewContactPersonForm.email;
    if( contactperson == '' || contactperson.trim().length == 0)
    {
	     errors = errors + "<li> Contact Person should not be empty";
         document.addNewContactPersonForm.newContactPerson.focus();
    }
    if( email.value != '' )
	{
        if( !IsValidEmail (email) )
        {
            errors = '<li>'+'Please enter a valid email address';
            email.select();
            email.focus();
        }
     }
    //added by varma 16 aug 2004 to restrict double quote in Contact Person name
    if( contactperson.indexOf('"') >= 0 )
    {
          errors = errors + "<li> Please Enter a Valid Contact Person Name";
          document.addNewContactPersonForm.newContactPerson.select();
          document.addNewContactPersonForm.newContactPerson.focus();

    }
    if(errors != '')
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return ;
    }

  /* var endUserId = window.opener.document.endUserForm['endUser.endUserId'].value;
   document.addNewContactPersonForm.action = '<%=chipTracContext%>/addNewEndUserContactPerson.do?action=insertContactPerson&endUserId=' + endUserId;
   */

   var endUserId = window.opener.document.endUserForm['endUser.endUserId'].value;
   var contactPersonValue = document.addNewContactPersonForm.contactPersonValue.value;
   var shippingAddressId = document.addNewContactPersonForm.endUserId.value;
   var action = '<%=request.getParameter("action")%>';

   if( action == 'editContactPerson' )
   {
        action = 'saveEditContactPerson' ;
   }
   else
   {
        action = 'insertContactPerson';
   }

   if( contactPersonValue =='EndUser')
	{
		document.addNewContactPersonForm.action = '<%=chipTracContext%>/addNewEndUserContactPerson.do?action='+action+'&value='+contactPersonValue+'&endUserId=' + endUserId;
	}

	if( contactPersonValue =='Address')
	{
		document.addNewContactPersonForm.action = '<%=chipTracContext%>/addNewEndUserContactPerson.do?action='+action+'&value='+contactPersonValue+'&endUserId=' + shippingAddressId;
	}

   document.addNewContactPersonForm.submit();
   return;
}
function reset(){
    document.addNewContactPersonForm.reset();
}

function closeWindow(form) {
    window.opener.document.endUserForm.submit();
 	window.close();
}

</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- from here your body starts -->

<html:form name="addNewContactPersonForm" type="com.scalar.chiptrack.sales.forms.AddNewContactPersonForm" scope="request" action="/addNewEndUserContactPerson.do?action=insertContactPerson">

<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<center><span class="NArialW">Contact Person</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>

<table border="0" width="500" cellpadding='0' cellspacing='0' align="center">

<tr><td align="center">

<table border="0" width="100%"  cellspacing="2" cellpadding='2' align='right'>
<tr><td colspan='4' align=right><a href="javascript:closeWindow(document.addNewContactPersonForm);" onMouseOver="window.status='Click to close this window';return true" onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>
<tr><td colspan='4'><chiptrack:errors styleClass='NArialL' /></td></tr>
<tr><td colspan='4'><chiptrack:info styleClass='NArialL' /></td></tr>


    <!--tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer/gif" height=10></td></tr-->
    <tr><td colspan='4' align="left" class='NArialL'><FONT id="errors" styleClass="NArialL" color='FF0000'></FONT></TD></TR>

	<tr>
        <td width="25%" align="right" nowrap><font class="NArialL">Contact Person :<font color=red>*</font></font></td>
		<td width="25%" ><html:text property="newContactPerson" size="20" styleClass="txfield" maxlength="50" />
		</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <%-- <td width="25%" align='right'><font class="NArialL">Address :&nbsp;&nbsp;</font></td>
        <td width="25%" ><html:text property="address" size="20" styleClass="txfield" maxlength="50" /></td> --%>
    </tr>
	<tr>
        <td width="25%" align="right"><font class="NArialL">Phone :&nbsp;&nbsp;</font></td>
		<td width="25%" ><html:text property="phoneNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
		</td>
        <td width="25%" align="right" nowrap><font class="NArialL">Cell No :&nbsp;&nbsp;</font></td>
		<td width="25%" ><html:text property="cellNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
		</td>
    </tr>
    <tr>
        <td width="25%" align="right"><font class="NArialL">Fax :&nbsp;&nbsp;</font></td>
		<td width="25%" ><html:text property="faxNumber" size="20" styleClass="txfield" maxlength="50" onkeypress='validatePhoneNumber(this)'/>
		</td>
        <td width="25%" align="right"><font class="NArialL">Email :&nbsp;&nbsp;</font></td>
		<td width="25%" ><html:text property="email" size="20" styleClass="txfield" maxlength="50" />
		</td>
    </tr>
     <%-- Added by Varma(25jun 2004)--%>
    <tr>
        <td align='left' colspan=2 nowrap><html:checkbox property="salesAckMail" value="true" /> <FONT class='NArialL'>Receive SalesOrder Acknowledge Mails </FONT></td>
        <td align='left'colspan=2 nowrap><html:checkbox property="shipAlerts" value="true" /> <font class="NArialL">Receive Ship Alert Mails</font></td>
    </tr>
    <tr>
        <td align='left' colspan=2 nowrap><html:checkbox property="proformaInvoice" value="true" /> <FONT class='NArialL'>Receive Proforma Invoice Mails </FONT></td>
        <td align='left'colspan=2 nowrap><html:checkbox property="packingSlip" value="true" /> <font class="NArialL">Receive Packing Slip Mails</font></td>
    </tr>
    <%--<tr>
        <td width="25%" align='left' colspan=2><html:checkbox property="commerInvoice" value="true" /> <FONT class='NArialL'>Receive Commercial Invoice Mails </FONT></td>
    </tr>--%>
    <%--till here by varma --%>
     <tr><td colspan=4><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
	<tr>
        <td colspan=4 align="center">
        <table widht="100%">
        <td colspan='2' nowrap align='right'>
        <%-- Commented by Krishna Prasad on 20 May 2004, due to improper submition of form --%>
		<%--<a href="javascript:save()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a>--%>
        <%-- Added by Krishna Prasad on 20 May 2004, due to above commented tag is not submiting the form properly--%>

        <!-- Commented by SureshReddy on [09 JUNE 2004] due to this line record is saving 2 times-->
        <!--<input type="image" onClick="javascript:return save();" border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"onmouseover="window.status='Click to Save Contact Person';return true;"onmouseout="window.status='';return true" title="Click here to Save Contact Person">-->

        <!-- Added by SureshReddy on [09 JUNE 2004] to save record 1 time-->
        <%-- <a href="#" onClick="javascript:return save()" onmouseover="window.status='Click to Save';return true;" onmouseout="window.status='';return true" title="Click here to Save"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a> --%>
        <%-- Added by veeru on 16th June 2004 to save contact person properly independent of the browser we are using --%>
        <chiptrack:restrictedLink functionality='<%=Functionality.CUSTOMER_DETAILS%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href="javascript:save()" onmouseover="window.status='Click to Save Contact Person';return true" onmouseout="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" title="Click here to Save Contact Person"/></chiptrack:restrictedLink>
	    </td>
		<td colspan='1' nowrap align='left'>
		<a href="javascript:reset()"onMouseOver="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"></a>
	    </td>
        </table>
        </td>
    </tr>

  </table>

  </td></tr>
  <tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
  <tr><td align="center">

<!-- DISPLAY ALL USERS STARTS HERE -->

<% ArrayList contactPersons = (ArrayList) request.getAttribute("contactPersons");
	if( contactPersons != null && contactPersons.size() != 0 ) { %>

   <table border="0" width="50%" bordercolor="#FFFFFF">
    <tr>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Contact Person</font></font></td>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Action</font></font></td>
    </tr>


    <logic:iterate id="ContactPerson" name="contactPersons" type="com.scalar.chiptrack.sales.ContactPerson">

	<% int bgcount = 0;%>
    <% bgcount = bgcount + 1; %>
    <tr>
    <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
    <bean:write name="ContactPerson" property="contactPerson" /></font></td>
    <td nowrap width="15%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
     <logic:equal name="ContactPerson" property="disabled" value="true">
     <a href='<%=chipTracContext%>/addNewEndUserContactPerson.do?contactPersonstatus=disable&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&endUserId=<%=request.getParameter("endUserId")%>&value=<%=request.getParameter("value")%>' onMouseOver="window.status='Click to Disable Contact Person';return true" onmouseout="window.status='';return true">Disable</a>
     </logic:equal>
     <logic:equal name="ContactPerson" property="disabled" value="false">
     <a href='<%=chipTracContext%>/addNewEndUserContactPerson.do?contactPersonstatus=activate&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&endUserId=<%=request.getParameter("endUserId")%>&value=<%=request.getParameter("value")%>' onMouseOver="window.status='Click to Activate Contact';return true" onmouseout="window.status='';return true"><font color='red'> Activate</font></a>
     </logic:equal>
     &nbsp;&nbsp;<a href='<%=chipTracContext%>/addNewEndUserContactPerson.do?action=editContactPerson&contactPerson=<bean:write name="ContactPerson" property="encodeContactPerson" />&endUserId=<%=request.getParameter("endUserId")%>&value=<%=request.getParameter("value")%>'onmouseover="window.status='Click to Edit Contact Person';return true;"onmouseout="window.status='';return true"> Edit </a>
     </font></td>

    </tr>


    </logic:iterate>
    <tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr>
    <tr><td colspan=3 align=center><a href="javascript:closeWindow(document.addNewContactPersonForm);" onMouseOver="window.status='Click here to close this window';return true" onmouseout="window.status='';return true"><font class='NArialL'>Close this window</font></a></td></tr>

    </table>
	<% } %>

<!-- DISPLAY ALL USERS ENDS HERE -->

</td></tr>
</table>
<input type="hidden" name="endUserId" value ='<%=request.getParameter("endUserId")%>' >
<input type="hidden" name="contactPersonValue" value ='<%=request.getParameter("value")%>' >

</html:form>



</body>

</html:html>